/**
 * @author alex
 */

package slave;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.Vector;
import commonUtility.LineUtility;
import commonUtility.XmlHandler;

/****************************************************************
 * CLASSE UTILIZZATA PER IL CALCOLO DEL LAMBDA
 ****************************************************************/	

public class LambdaComputationThread extends Thread {
	private XmlHandler xml;
	private int coding;
	public LambdaComputationThread(XmlHandler xmlSynchronized, int currentQuality){
		this.xml = xmlSynchronized;
		this.coding=currentQuality;
	}	
	public void run(){
		StringTokenizer st = null;
		String delim = ":";
		boolean moreLines = true;	
		BufferedReader in = null;
		try {
			in = new BufferedReader(new FileReader("./slaveTmp/inquiry.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		Vector<String> info = new Vector<String>();
		while (moreLines) {
			//estrazione della linea
			String linea = LineUtility.getNextLine(in);
				if (linea.equals("Nessuna linea disponibile")) { 
				moreLines = false;
				break; //esco dal ciclo
			}	
			st = new StringTokenizer(linea);
			while(st.hasMoreTokens()){
				try{
					String mac = st.nextToken(delim);	
					int rssi = Integer.parseInt(st.nextToken(delim));
					info.add(0,mac);
					info.add(1,null);
					info.add(2,null);
					info.add(3,null);
					info.add(4,null);
					info.add(5,null);
					info.add(6,Integer.toString(rssi));	
					info.add(7,Integer.toString(coding));	
					xml.changeStatusClientXml("update",info);
				}catch(NoSuchElementException e) {
					e.printStackTrace();
					continue;
				}
			}			   

		}//fine while(moreLines)   
	}	

	public static void main(String args[]) {

	
	}
}
